﻿using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Literary.Core.Common.Input;
using Literary.Core.Common.Output;
using Literary.Core.Service.Business.Material.ArticleCategory;
using Literary.Core.Model.Business.Material;
using Literary.Core.Service.Business.Material.ArticleCategory.Input;

namespace Literary.Core.Controllers.Business.Material
{
    /// <summary>
    /// 文章分类管理
    /// </summary>
    public class ArticleCategoryController : AreaController
    {
        private readonly IArticleCategoryService _articleCategoryServices;

        public ArticleCategoryController(IArticleCategoryService articleCategoryServices)
        {
            _articleCategoryServices = articleCategoryServices;
        }

        /// <summary>
        /// 查询单条分类
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IResponseOutput> Get(long id)
        {
            return await _articleCategoryServices.GetAsync(id);
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="input">分页模型</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IResponseOutput> GetPage(PageInput<ArticleCategoryEntity> input)
        {
            return await _articleCategoryServices.PageAsync(input);
        }

        /// <summary>
        /// 查询列表
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IResponseOutput> GetList(string key) 
        {
            return await _articleCategoryServices.GetListAsync(key);
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IResponseOutput> Add(ArticleCategoryAddInput input)
        {
            return await _articleCategoryServices.AddAsync(input);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IResponseOutput> Update(ArticleCategoryUpdateInput input)
        {
            return await _articleCategoryServices.UpdateAsync(input);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IResponseOutput> SoftDelete(long id)
        {
            return await _articleCategoryServices.SoftDeleteAsync(id);
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IResponseOutput> BatchSoftDelete(long[] ids)
        {
            return await _articleCategoryServices.BatchSoftDeleteAsync(ids);
        }
    }
}
